# coding=utf-8

import base64

import pymysql

host = "47.99.215.64"
user_name = "root"
password = b'VGlhbnhpYWRpeWkxMjM='
port = 5407
database = "test"


def get_connect_mysql():
    conn = pymysql.connect(host=host, user=user_name, password=base64.b64decode(password).decode(), port=port,
                           database=database)
    return conn


def test_insert():
    """
    插入数据
    """
    conn = get_connect_mysql()
    cursor = conn.cursor()
    sql = "insert user_name (name,age) values(%s,%s)"

    cursor.execute(sql, ("summit", 18))
    conn.commit()
    conn.close()


def test_select():
    conn = get_connect_mysql()
    cursor = conn.cursor()
    sql = "select * from user_name"
    cursor.execute(sql)

    # all = cursor.fetchall()
    one = cursor.fetchone()
    any = cursor.fetchmany(2)
    #  print(all)
    print(one)
    print(any)


if __name__ == '__main__':
    # test_insert()
    test_select()
